
import { useUserStore } from '@stores/user'

export default {
  mounted(el, binding) {
    const { value } = binding
    if (value && value instanceof Array && value.length > 0) {
      const user = useUserStore()
      const all_permission = "*:*:*"; // 所有权限
      const permissions = user.permissions
      const permissionFlag = value // 自定义指令传入值

      const hasPermissions = permissions.some(permission => {
        return all_permission === permission || permissionFlag.includes(permission)
      })

      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  },
}
